package com.societyGames.faceExercises
{
import com.pblabs.engine.serialization.ISerializable;

import flash.utils.Dictionary;

public class FaceData implements ISerializable
{
  private var _name:String;
  private var _traits:Dictionary = new Dictionary();

  public function serialize(xml:XML):void
  {
  }

  public function deserialize(xml:XML):*
  {
    this._name = xml.name[0].toString();
    var text:String = xml.traits[0].toString();
    var textParts:Array = text.split(",");
    for each (var textPart:String in textParts)
    {
      var keyValue:Array = textPart.split(":");
      this._traits[keyValue[0]] = keyValue[1];
    }
    return this;
  }

  public function get name():String
  {
    return this._name;
  }

  public function getTrait(trait:String):String
  {
    return this._traits[trait];
  }

  public function get isWearingGlasses():Boolean
  {
    return getTrait("Glasses") == "Yes";
  }

  public function get isWearingHat():Boolean
  {
    var trait:String = getTrait("Hat");
    return !(trait == null || trait == "No");
  }

  public function get age():Number
  {
    var trait:String = getTrait("Age");
    return Number(trait);
  }
}
}